<?php

class Ext_Login
{
    protected static $_instance = null;
    protected $_controller = null;
    protected $_validater = null;
    protected $_checker = null;
    
    public static function getInstance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }
    
    public function __construct($controller)
    {
        $this->_controller = $controller;
    }
    
    public function showForm()
    {
        $_showFormer = new Ext_Login_ShowForm_Adapter($this->_controller);
        $_showFormer->showForm();
    }
    
    public function validate()
    {
        $_validater = new Ext_Login_Validate_Adapter($this->_controller);
        $_validater->getAdapter()->validate();

        $this->_validater = $_validater;
    }
    
    public function getValidater()
    {
        return $this->_validater->getAdapter();
    }
    
    public function check()
    {
        $_checker = new Ext_Login_Check_Adapter($this->getValidater()->getResult()->getData());
        $_checker->getAdapter()->check();
        
        $this->_checker = $_checker;
    }
    
    public function getChecker()
    {
        return $this->_checker->getAdapter();
    }
    
    public function oauth()
    {
        if($this->getValidater()->isOauth())
        {
            $_oauth = Ext_Oauth::getInstance();
		    $_oauth->setBind($this->getChecker()->getResult()->getIdentity());
        }
    }
    
    public function auth()
    {
        $_auther = Ext_Auth::getInstance();
        $_auther->auth($this->getChecker()->getResult()->getIdentity());
    }
}
